package com.tecode.myBooks.shoppingCart.service;

import com.tecode.myBooks.shoppingCart.dao.ShoppingDao;

/**
 * Created with Intellij IDEA.
 *
 * @Author: Gabriel
 * @Date: 2018-12-10
 * @Description:
 */
public class ShoppingService {
	private  ShoppingDao shoppingDao = new ShoppingDao();
	public boolean addCart(String productId, int nums, int userId) {
		int rows = 0;
		//1.判断购物车中是否存在该用户的商品
			boolean flag = shoppingDao.getShoppCartByUserIdAndproductId(productId,userId);

			if(flag){
				rows = shoppingDao.updateShoppCartByUserIdAndproductId(productId, nums, userId);
			}else {
				rows = shoppingDao.addCart(productId, nums, userId);
			}
		return  rows >0;


	}
}